Note
Click here to download the full example code
RecoBundles80 using AFQ API¶
An example using the AFQ API to run recobundles with the 80 bundle atlas.
import os.path as op
import plotly
from AFQ import api
import AFQ.data as afd
Get some example data¶
Retrieves Stanford HARDI dataset.
afd.organize_stanford_data(clear_previous_afq=True)
Out:
0%| | 0/5578 [00:00<?, ? MB/s]
0%| | 8/5578 [00:00<01:22, 67.59 MB/s]
0%| | 25/5578 [00:00<00:49, 111.39 MB/s]
1%|1 | 56/5578 [00:00<00:30, 178.92 MB/s]
2%|1 | 95/5578 [00:00<00:23, 234.76 MB/s]
2%|2 | 135/5578 [00:00<00:20, 269.65 MB/s]
3%|3 | 174/5578 [00:00<00:17, 305.63 MB/s]
4%|3 | 207/5578 [00:00<00:18, 296.04 MB/s]
4%|4 | 246/5578 [00:00<00:17, 304.90 MB/s]
5%|5 | 286/5578 [00:01<00:16, 313.78 MB/s]
6%|5 | 326/5578 [00:01<00:16, 320.13 MB/s]
7%|6 | 366/5578 [00:01<00:16, 323.54 MB/s]
7%|7 | 405/5578 [00:01<00:16, 322.38 MB/s]
8%|7 | 445/5578 [00:01<00:15, 325.12 MB/s]
9%|8 | 485/5578 [00:01<00:15, 327.80 MB/s]
9%|9 | 525/5578 [00:01<00:15, 328.31 MB/s]
10%|# | 564/5578 [00:01<00:15, 327.44 MB/s]
11%|# | 599/5578 [00:02<00:15, 326.94 MB/s]
11%|#1 | 636/5578 [00:02<00:14, 329.77 MB/s]
12%|#2 | 670/5578 [00:02<00:15, 326.88 MB/s]
13%|#2 | 707/5578 [00:02<00:14, 329.72 MB/s]
13%|#3 | 741/5578 [00:02<00:14, 327.67 MB/s]
14%|#3 | 779/5578 [00:02<00:14, 331.76 MB/s]
15%|#4 | 813/5578 [00:02<00:14, 329.00 MB/s]
15%|#5 | 850/5578 [00:02<00:14, 330.79 MB/s]
16%|#5 | 884/5578 [00:02<00:14, 328.57 MB/s]
17%|#6 | 922/5578 [00:02<00:13, 333.31 MB/s]
17%|#7 | 956/5578 [00:03<00:14, 328.50 MB/s]
18%|#7 | 993/5578 [00:03<00:13, 333.14 MB/s]
18%|#8 | 1027/5578 [00:03<00:14, 324.28 MB/s]
19%|#9 | 1065/5578 [00:03<00:13, 335.42 MB/s]
20%|#9 | 1099/5578 [00:03<00:13, 326.89 MB/s]
20%|## | 1136/5578 [00:03<00:13, 334.32 MB/s]
21%|## | 1170/5578 [00:03<00:13, 322.71 MB/s]
22%|##1 | 1208/5578 [00:03<00:12, 338.13 MB/s]
22%|##2 | 1242/5578 [00:03<00:13, 323.29 MB/s]
23%|##2 | 1280/5578 [00:04<00:13, 320.96 MB/s]
24%|##3 | 1320/5578 [00:04<00:13, 325.09 MB/s]
24%|##4 | 1360/5578 [00:04<00:12, 327.91 MB/s]
25%|##5 | 1400/5578 [00:04<00:12, 329.34 MB/s]
26%|##5 | 1439/5578 [00:04<00:12, 328.78 MB/s]
27%|##6 | 1479/5578 [00:04<00:12, 329.30 MB/s]
27%|##7 | 1519/5578 [00:04<00:12, 328.97 MB/s]
28%|##7 | 1559/5578 [00:04<00:12, 330.92 MB/s]
29%|##8 | 1593/5578 [00:05<00:12, 329.84 MB/s]
29%|##9 | 1630/5578 [00:05<00:12, 323.32 MB/s]
30%|##9 | 1670/5578 [00:05<00:11, 325.94 MB/s]
31%|### | 1710/5578 [00:05<00:11, 328.58 MB/s]
31%|###1 | 1749/5578 [00:05<00:11, 327.45 MB/s]
32%|###2 | 1789/5578 [00:05<00:11, 329.87 MB/s]
33%|###2 | 1822/5578 [00:05<00:11, 329.20 MB/s]
33%|###3 | 1861/5578 [00:05<00:11, 327.81 MB/s]
34%|###4 | 1900/5578 [00:05<00:11, 326.73 MB/s]
35%|###4 | 1940/5578 [00:06<00:11, 329.11 MB/s]
35%|###5 | 1980/5578 [00:06<00:10, 330.18 MB/s]
36%|###6 | 2020/5578 [00:06<00:10, 330.49 MB/s]
37%|###6 | 2059/5578 [00:06<00:10, 329.90 MB/s]
38%|###7 | 2099/5578 [00:06<00:10, 331.30 MB/s]
38%|###8 | 2139/5578 [00:06<00:10, 333.33 MB/s]
39%|###8 | 2175/5578 [00:06<00:10, 340.20 MB/s]
40%|###9 | 2210/5578 [00:06<00:10, 329.28 MB/s]
40%|#### | 2247/5578 [00:07<00:09, 339.46 MB/s]
41%|#### | 2282/5578 [00:07<00:09, 330.18 MB/s]
42%|####1 | 2316/5578 [00:07<00:09, 331.84 MB/s]
42%|####2 | 2350/5578 [00:07<00:09, 329.51 MB/s]
43%|####2 | 2385/5578 [00:07<00:09, 331.15 MB/s]
43%|####3 | 2419/5578 [00:07<00:09, 323.62 MB/s]
44%|####4 | 2457/5578 [00:07<00:09, 335.54 MB/s]
45%|####4 | 2491/5578 [00:07<00:09, 325.02 MB/s]
45%|####5 | 2528/5578 [00:07<00:09, 335.06 MB/s]
46%|####5 | 2562/5578 [00:07<00:09, 323.45 MB/s]
47%|####6 | 2600/5578 [00:08<00:09, 323.19 MB/s]
47%|####7 | 2633/5578 [00:08<00:09, 317.61 MB/s]
48%|####7 | 2672/5578 [00:08<00:09, 319.21 MB/s]
49%|####8 | 2711/5578 [00:08<00:08, 331.34 MB/s]
49%|####9 | 2745/5578 [00:08<00:08, 324.87 MB/s]
50%|####9 | 2783/5578 [00:08<00:08, 323.65 MB/s]
51%|##### | 2822/5578 [00:08<00:08, 336.08 MB/s]
51%|#####1 | 2856/5578 [00:08<00:08, 325.56 MB/s]
52%|#####1 | 2894/5578 [00:08<00:08, 325.36 MB/s]
52%|#####2 | 2928/5578 [00:09<00:08, 329.35 MB/s]
53%|#####3 | 2965/5578 [00:09<00:07, 326.71 MB/s]
54%|#####3 | 2999/5578 [00:09<00:07, 330.05 MB/s]
54%|#####4 | 3037/5578 [00:09<00:07, 327.81 MB/s]
55%|#####5 | 3070/5578 [00:09<00:07, 328.36 MB/s]
56%|#####5 | 3108/5578 [00:09<00:07, 329.47 MB/s]
56%|#####6 | 3141/5578 [00:09<00:07, 329.06 MB/s]
57%|#####7 | 3180/5578 [00:09<00:07, 332.33 MB/s]
58%|#####7 | 3214/5578 [00:09<00:07, 334.25 MB/s]
58%|#####8 | 3248/5578 [00:10<00:06, 334.05 MB/s]
59%|#####8 | 3283/5578 [00:10<00:07, 320.64 MB/s]
60%|#####9 | 3323/5578 [00:10<00:06, 324.79 MB/s]
60%|###### | 3363/5578 [00:10<00:06, 327.49 MB/s]
61%|###### | 3402/5578 [00:10<00:06, 326.73 MB/s]
62%|######1 | 3442/5578 [00:10<00:06, 328.57 MB/s]
62%|######2 | 3475/5578 [00:10<00:06, 325.23 MB/s]
63%|######2 | 3513/5578 [00:10<00:06, 322.42 MB/s]
64%|######3 | 3553/5578 [00:11<00:06, 323.35 MB/s]
64%|######4 | 3593/5578 [00:11<00:06, 323.78 MB/s]
65%|######5 | 3633/5578 [00:11<00:05, 326.54 MB/s]
66%|######5 | 3673/5578 [00:11<00:05, 329.35 MB/s]
67%|######6 | 3710/5578 [00:11<00:05, 340.06 MB/s]
67%|######7 | 3745/5578 [00:11<00:05, 325.66 MB/s]
68%|######7 | 3784/5578 [00:11<00:05, 327.34 MB/s]
69%|######8 | 3823/5578 [00:11<00:05, 326.63 MB/s]
69%|######9 | 3859/5578 [00:11<00:05, 335.32 MB/s]
70%|######9 | 3895/5578 [00:12<00:05, 327.38 MB/s]
70%|####### | 3930/5578 [00:12<00:04, 332.93 MB/s]
71%|#######1 | 3966/5578 [00:12<00:04, 327.56 MB/s]
72%|#######1 | 3999/5578 [00:12<00:04, 328.05 MB/s]
72%|#######2 | 4033/5578 [00:12<00:04, 331.05 MB/s]
73%|#######2 | 4069/5578 [00:12<00:04, 329.02 MB/s]
74%|#######3 | 4102/5578 [00:12<00:04, 328.13 MB/s]
74%|#######4 | 4138/5578 [00:12<00:04, 334.16 MB/s]
75%|#######4 | 4173/5578 [00:12<00:04, 325.96 MB/s]
75%|#######5 | 4209/5578 [00:12<00:04, 331.85 MB/s]
76%|#######6 | 4244/5578 [00:13<00:04, 331.87 MB/s]
77%|#######6 | 4278/5578 [00:13<00:03, 331.94 MB/s]
77%|#######7 | 4312/5578 [00:13<00:03, 329.19 MB/s]
78%|#######7 | 4347/5578 [00:13<00:03, 330.78 MB/s]
79%|#######8 | 4381/5578 [00:13<00:03, 331.86 MB/s]
79%|#######9 | 4415/5578 [00:13<00:03, 327.48 MB/s]
80%|#######9 | 4451/5578 [00:13<00:03, 328.70 MB/s]
80%|######## | 4486/5578 [00:13<00:03, 327.36 MB/s]
81%|########1 | 4522/5578 [00:13<00:03, 329.52 MB/s]
82%|########1 | 4555/5578 [00:14<00:03, 326.74 MB/s]
82%|########2 | 4589/5578 [00:14<00:02, 330.45 MB/s]
83%|########2 | 4625/5578 [00:14<00:02, 324.56 MB/s]
84%|########3 | 4663/5578 [00:14<00:02, 339.90 MB/s]
84%|########4 | 4698/5578 [00:14<00:02, 327.11 MB/s]
85%|########4 | 4736/5578 [00:14<00:02, 323.83 MB/s]
86%|########5 | 4775/5578 [00:14<00:02, 342.12 MB/s]
86%|########6 | 4810/5578 [00:14<00:02, 329.44 MB/s]
87%|########6 | 4844/5578 [00:14<00:02, 330.77 MB/s]
87%|########7 | 4879/5578 [00:15<00:02, 323.36 MB/s]
88%|########8 | 4914/5578 [00:15<00:02, 328.71 MB/s]
89%|########8 | 4950/5578 [00:15<00:01, 325.64 MB/s]
89%|########9 | 4985/5578 [00:15<00:01, 328.30 MB/s]
90%|######### | 5022/5578 [00:15<00:01, 327.27 MB/s]
91%|######### | 5057/5578 [00:15<00:01, 332.13 MB/s]
91%|#########1| 5093/5578 [00:15<00:01, 320.77 MB/s]
92%|#########2| 5133/5578 [00:15<00:01, 325.27 MB/s]
93%|#########2| 5172/5578 [00:15<00:01, 325.80 MB/s]
93%|#########3| 5208/5578 [00:16<00:01, 335.01 MB/s]
94%|#########4| 5244/5578 [00:16<00:01, 328.23 MB/s]
95%|#########4| 5280/5578 [00:16<00:00, 336.63 MB/s]
95%|#########5| 5315/5578 [00:16<00:00, 326.46 MB/s]
96%|#########5| 5351/5578 [00:16<00:00, 335.68 MB/s]
97%|#########6| 5387/5578 [00:16<00:00, 328.29 MB/s]
97%|#########7| 5427/5578 [00:16<00:00, 330.30 MB/s]
98%|#########7| 5462/5578 [00:16<00:00, 335.07 MB/s]
99%|#########8| 5498/5578 [00:16<00:00, 329.00 MB/s]
99%|#########9| 5533/5578 [00:17<00:00, 334.23 MB/s]
100%|#########9| 5569/5578 [00:17<00:00, 327.41 MB/s]
100%|##########| 5578/5578 [00:17<00:00, 325.37 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 4514.86 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 3515.76 MB/s]
0%| | 0/71 [00:00<?, ? MB/s]
11%|#1 | 8/71 [00:00<00:00, 67.68 MB/s]
37%|###6 | 26/71 [00:00<00:00, 116.90 MB/s]
75%|#######4 | 53/71 [00:00<00:00, 179.43 MB/s]
100%|##########| 71/71 [00:00<00:00, 182.53 MB/s]
0%| | 0/4 [00:00<?, ? MB/s]
100%|##########| 4/4 [00:00<00:00, 81.67 MB/s]
0%| | 0/1 [00:00<?, ? MB/s]
100%|##########| 1/1 [00:00<00:00, 5336.26 MB/s]
Set tractography parameters (optional)¶
We make this tracking_params which we will pass to the AFQ object which specifies that we want 50,000 seeds randomly distributed in the white matter.
We only do this to make this example faster and consume less space.
tracking_params = dict(n_seeds=50000,
random_seeds=True,
rng_seed=42)
Initialize an AFQ object:¶
We specify seg_algo as reco80 in segmentation_params. This tells the AFQ object to perform RecoBundles using the 80 bundles atlas in the segmentation step.
myafq = api.AFQ(bids_path=op.join(afd.afq_home,
'stanford_hardi'),
preproc_pipeline='vistasoft',
segmentation_params={"seg_algo": "reco80"},
tracking_params=tracking_params)
Out:
Downloading https://templateflow.s3.amazonaws.com/tpl-MNI152NLin2009cAsym/tpl-MNI152NLin2009cAsym_res-01_T1w.nii.gz
0%| | 0.00/13.4k [00:00<?, ?B/s]
0%| | 36.0/13.4k [00:00<00:50, 262B/s]
1%|1 | 172/13.4k [00:00<00:19, 686B/s]
5%|5 | 733/13.4k [00:00<00:05, 2.22kB/s]
22%|##2 | 2.96k/13.4k [00:00<00:01, 7.65kB/s]
54%|#####3 | 7.16k/13.4k [00:00<00:00, 15.8kB/s]
85%|########4 | 11.3k/13.4k [00:00<00:00, 20.5kB/s]
13.4kB [00:00, 15.4kB/s]
Downloading https://templateflow.s3.amazonaws.com/tpl-MNI152NLin2009cAsym/tpl-MNI152NLin2009cAsym_res-01_desc-brain_mask.nii.gz
0%| | 0.00/155 [00:00<?, ?B/s]
22%|##1 | 34.0/155 [00:00<00:00, 242B/s]
88%|########7 | 136/155 [00:00<00:00, 522B/s]
156B [00:00, 547B/s]
Visualizing bundles and tract profiles:¶
This would run the script and visualize the bundles using the plotly interactive visualization, which should automatically open in a new browser window.
bundle_html = myafq.all_bundles_figure
plotly.io.show(bundle_html["01"])